from django.shortcuts import render
from django.http import HttpResponse
from .models import cal

# Create your views here.

def acticle(request):
    print('已进入后台')
    return render(request, 'acticle.html')

def CalPage(request):
    return render(request, 'cal.html')

def Cal(request):
    if request.method == 'POST':
        a = request.POST['valueA']
        b = request.POST['valueB']
        result = int(a) + int(b)
        cal.objects.create(a=a,b=b,result=result)
        return render(request, 'result.html', context={'data': result})
    else:
        return HttpResponse('please visit us with POST')

def CalList(request):
    data = cal.objects.all()
    # for i in data:
    #     print(i.a, i.b, i.result)
    return render(request, 'list.html', context={'data': data})

def DelData(request):
    cal.objects.all().delete()
    return HttpResponse('data Deleted')